package com.woniuxy.exam.service;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.woniuxy.exam.entity.Book;
import com.woniuxy.exam.mapper.BookMapper;
import com.woniuxy.exam.vo.BookVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class BookService {

    @Autowired
    BookMapper bookMapper ;

    public PageInfo<BookVo> findBookByPage(Integer now,Integer size,String name,Integer cid){
        PageHelper.startPage(now,size);
        List<BookVo> list = bookMapper.selectBookByNameAndCid(name, cid);
        return new PageInfo<>(list);
    }

    public void add(Book book) {
        bookMapper.insert(book);
    }

    public void modify(Book book) {
        bookMapper.updateByPrimaryKey(book);
    }

    public int removeBookByKey(int id) {

        return bookMapper.deleteByPrimaryKey(id);
    }

    public int removeBatch(int[] ids) {
        return bookMapper.deleteBatch(ids);
    }

    public Book findBookByKey(int id) {
        return bookMapper.selectByPrimaryKey(id);
    }
}
